package net.myspring.rabbit.receiver;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author wangzm
 */
@Component
@RabbitListener(queues = "hello",group = "2")
public class FanoutController {

    @RabbitListener(queues = "fanout.A")
    public void on(Message message, Channel channel) throws IOException {
        //消费失败 不放回队列进死信
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), true,false);
        System.out.println("fanout.A : " + message);
    }

    @RabbitHandler
    @RabbitListener(queues = "fanout.B")
    public void fanoutB(Message message, Channel channel) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        System.out.println("fanout.B : " + message);
    }

    @RabbitHandler
    @RabbitListener(queues = "fanout.C")
    public void fanoutC(Message message, Channel channel) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        System.out.println("fanout.C : " + message);
    }
}
